package com.example.kaoshi;

import java.util.Scanner;

/**
 * Created by Quincy on 2018/8/30.
 */
public class Test4 {
//    public static int maxProfit(int prices[]) {
//        int maxprofit = 0;
//        for (int i = 0; i < prices.length - 1; i++) {
//            for (int j = i + 1; j < prices.length; j++) {
//                int profit = prices[j] - prices[i];
//                if (profit > maxprofit)
//                    maxprofit = profit;
//            }
//        }
//        return maxprofit;
//    }
public static int maxProfit(int prices[]) {
    int minprice = Integer.MAX_VALUE;
    int maxprofit = 0;
    for (int i = 0; i < prices.length; i++) {
        if (prices[i] < minprice)
            minprice = prices[i];
        else if (prices[i] - minprice > maxprofit)
            maxprofit = prices[i] - minprice;
    }
    return maxprofit;
}
    public static int[] StringToIntArr(String str){

        char[] arr = new char[str.length()];
        int[] arr2 = new int[str.length()];
        arr = str.toCharArray();
        for(int i=0; i<str.length(); i++){
            arr2[i] = arr[i] - 48;
        }
        return arr2;

    }

    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        String read = scan.nextLine();
        int[] prices = StringToIntArr(read.replaceAll(" ",""));
        System.out.println(read.replaceAll(" ",""));
        int a = maxProfit(prices);
        System.out.println(a);
    }

}
